# _*_ encoding:utf-8 _*_

from rest_framework import serializers

from orders.models import OrderInfo, OrderGoods
from goods.models import SKU


class SKUSimpleModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = SKU
        fields = ['name', 'default_image']


class OrderGoodsModelSerializer(serializers.ModelSerializer):
    sku = SKUSimpleModelSerializer()

    class Meta:
        model = OrderGoods
        fields = ['count', 'price', 'sku']


class OrderDetailModelSerialize(serializers.ModelSerializer):
    user = serializers.StringRelatedField
    skus = OrderGoodsModelSerializer(many=True)

    class Meta:
        model = OrderInfo
        exclude = ['address', 'update_time']


class OrderSimpleModelSerialize(serializers.ModelSerializer):

    class Meta:
        model = OrderInfo
        fields = ['order_id', 'create_time', 'status']

        extra_kwargs = {
            'create_time': {'format': '%Y-%m-%d'},
            'status': {'write_only': True}
        }

